


***********************************;
** HEDIS2010 datafile cleaning   **;
***********************************;

options ls=76 nofmterr;

libname raw '/data/Medicare_P01_2009/data/HEDIS/rawdata';
libname new '/data/Medicare_P01_2009/data/HEDIS/sasdata';


data a00; set raw.hedis2010data;

     length hic_org $ 18 ;
     hic_org=org_id||'-'||hic_number;

     ** Invalid HIC number Indicators **;

     if substr(hic_number,2,11)=' ' or
        substr(hic_number,3,10)=' ' or 
        substr(hic_number,4,9) =' ' or
        substr(hic_number,5,8) =' ' then short_hic=1; else short_hic=0;

      if hic_number=' ' or
         hic_number='00000' or
         hic_number='000000' or
         hic_number='0000000' or
         hic_number='00000000' or
         hic_number='000000000' or
         hic_number='0000000000' or
         hic_number='00000000000' or
         hic_number='000000000000' or

         hic_number='99999' or
         hic_number='999999' or
         hic_number='9999999' or
         hic_number='99999999' or
         hic_number='999999999' or
         hic_number='9999999999' or
         hic_number='99999999999' or
         hic_number='999999999999' or  
         hic_number='Error' or
         hic_number='NA' or 
         hic_number='UNKNOWN' then invalid_hic=1; else invalid_hic=0; 

       **** Exclude Invalid Cases ****;

       if short_hic=1 or invalid_hic=1 then delete;  /** Excluded 74 short and 213 invalid HIC numbers **/

       if m_months=0 then delete;  /** delete zero enrollment <0.6% sample **/

       proc sort; by hic_org;

 data a0; set a00;

       proc means data=a0 sum noprint nway;
            class hic_org;
            var m_months;
            output out=t0 sum=totmonth;

       proc sort data=t0; by hic_org;

data hedcle; merge a00 t0; by hic_org;


     id_num=_n_;

      if totmonth>12 then delete;  /** delete cases with more than 12 month enrollment **/
   

*** Outpupt LINKID2010 ***;

     data raw.linkid2010; set hedcle;

          keep hic_number id_num ;


data b0; set hedcle; 


      *******************************************************;
      **  Clean up HEDIS measures based on specification   **;
      *******************************************************;

      **--- Set Missing Information to . ---**;

      array list1  ABA_D     ABA_N     COL_D     COL_N     BCS_D     BCS_N     OMW_D     OMW_N     CBP_D     CBP_N         
                   PBH_D     PBH_N     CMC_D     CMC_N1    CMC_N2    CDC_D1    CDC_N1    CDC_D2    CDC_N2
                   CDC_D3    CDC_N3    CDC_D4    CDC_N4    CDC_D5    CDC_N5    CDC_D6    CDC_N6    CDC_D7    CDC_N7    
                   CDC_D8    CDC_N8    CDC_D9    CDC_N9    SPR_D     SPR_N     AMM_D     AMM_N1    AMM_N2  
                   GSO_D     GSO_N     ART_D     ART_N     MPM_D1    MPM_N1    MPM_D2    MPM_N2    MPM_D3    MPM_N3    
                   MPM_D4    MPM_N4    DAE_D     DAE_N1    DAE_N2    
                   DDE_D_HOF     DDE_N_HOF      DDE_D_DEMEN    DDE_N_DEMEN    DDE_D_CRF    DDE_N_CRF     
                   AAP_D_20_44   AAP_N_20_44    AAP_D_45_64    AAP_N_45_64    AAP_D_65     AAP_N_65         
                   IET_D_13_17   IET_NI_13_17   IET_NE_13_17   IET_D_18       IET_NI_18    IET_NE_18 
                   IAD_N_SVCANY  IAD_N_SVCIP    IAD_N_SVCINT   IAD_N_SVCAMB
                   MPT_N_ANYMHS  MPT_N_IPMHS    MPT_N_IMHS     MPT_N_EDHS ;
      do over list1; if list1<0 or list1>=9 then list1=.; end; 

      array list2  PCE_D  PCE_N1   PCE_N2   FUH_D   FUH_N1   FUH_N2;
      do over list2; if list2<0 or list2>=99 then list2=.; end;

      array list3  FSP_N_BWLS    FSP_N_CABG    FSP_N_PTCA   FSP_N_CC      FSP_N_CE      FSP_N_OCH    FSP_N_CCH
                   FSP_N_BS      FSP_N_AH      FSP_N_VH     FSP_N_PROS    FSP_N_THR     FSP_N_TKR    FSP_N_MAST       
                   FSP_N_LUMP    IPU_T_ACDI    IPU_T_ACDY   IPU_T_ACMEDI  IPU_T_ACMEDY  IPU_T_ACSDI  IPU_T_ACSDY      
                   IPU_T_ACMADI  IPU_T_ACMADY  AMB_T_OV     AMB_T_ED ;
      do over list3; if list3<0 or list3>=999 then list3=.; end;

      array list4   ABX_T_RX      ABX_T_RXDY     ABX_T_RXCRN    ABX_T_QUINO   ABX_T_CEPHA   ABX_T_AZITH
                    ABX_T_AMOXI   ABX_T_KETOL    ABX_T_CLIND    ABX_T_CMISC   ABX_T_ABSOR   ABX_T_AMINO
                    ABX_T_1GNCE   ABX_T_LINCO    ABX_T_MACRO    ABX_T_PENIC   ABX_T_TETRA   ABX_T_MISC ;
      do over list4; if list4<0 or list4>=9999 then list4=.;  end;

      if ABA_D = 0 AND ABA_N >0 THEN ABA_D=.; IF ABA_D<=0 then ABA_N = . ; 
      if COL_D = 0 AND COL_N >0 THEN COL_D=.; IF COL_D<=0 then COL_N = . ;
      if BCS_D = 0 AND BCS_N >0 THEN BCS_D=.; IF BCS_D<=0 then BCS_N = . ;    
      if OMW_D = 0 AND OMW_N >0 THEN OMW_D=.; IF OMW_D<=0 then OMW_N = . ;
      if CBP_D = 0 AND CBP_N >0 THEN CBP_D=.; IF CBP_D<=0 then CBP_N = . ;
      if PBH_D = 0 AND PBH_N >0 THEN PBH_D=.; IF PBH_D<=0 then PBH_N = . ;
      if CMC_D = 0 AND (CMC_N1>0 OR CMC_N2>0) THEN CMC_D=.; IF CMC_D<=0 then do; CMC_N1 = .;  CMC_N2 = .;  end;

      if CDC_D1 = 0 AND CDC_N1>0 THEN CDC_D1=.; IF CDC_D1<=0 then CDC_N1 = . ;
      if CDC_D2 = 0 AND CDC_N2>0 THEN CDC_D2=.; IF CDC_D2<=0 then CDC_N2 = . ;
      if CDC_D3 = 0 AND CDC_N3>0 THEN CDC_D3=.; IF CDC_D3<=0 then CDC_N3 = . ;
      if CDC_D4 = 0 AND CDC_N4>0 THEN CDC_D4=.; IF CDC_D4<=0 then CDC_N4 = . ;
      if CDC_D5 = 0 AND CDC_N5>0 THEN CDC_D5=.; IF CDC_D5<=0 then CDC_N5 = . ;    
      if CDC_D6 = 0 AND CDC_N6>0 THEN CDC_D6=.; IF CDC_D6<=0 then CDC_N6 = . ;
      if CDC_D7 = 0 AND CDC_N7>0 THEN CDC_D7=.; IF CDC_D7<=0 then CDC_N7 = . ;
      if CDC_D8 = 0 AND CDC_N8>0 THEN CDC_D8=.; IF CDC_D8<=0 then CDC_N8 = . ;   
      if CDC_D9 = 0 AND CDC_N9>0 THEN CDC_D9=.; IF CDC_D9<=0 then CDC_N9 = . ;
   
      if SPR_D = 0  AND SPR_N>0  THEN CDC_D1=.; IF SPR_D<=0 then SPR_N = . ; 
 
      if AMM_D = 0 AND (AMM_N1>0 OR AMM_N2>0) THEN AMM_D=.; IF AMM_D<=0 then do; AMM_N1 = .; AMM_N2 = .; end;
      if GSO_D = 0 AND GSO_N>0 THEN GSO_D=.; IF GSO_D<=0 then GSO_N = . ;
      if ART_D = 0 AND ART_N>0 THEN ART_D=.; IF ART_D<=0 then ART_N = . ;
 
      if MPM_D1 = 0 AND MPM_N1>0 THEN MPM_D1=.; IF MPM_D1<=0 then MPM_N1 = . ;
      if MPM_D2 = 0 AND MPM_N2>0 THEN MPM_D2=.; IF MPM_D2<=0 then MPM_N2 = . ;
      if MPM_D3 = 0 AND MPM_N3>0 THEN MPM_D3=.; IF MPM_D3<=0 then MPM_N3 = . ;
      if MPM_D4 = 0 AND MPM_N4>0 THEN MPM_D4=.; IF MPM_D4<=0 then MPM_N4 = . ;    

      if DAE_D = 0 AND (DAE_N1>0 OR DAE_N2>0) THEN DAE_D=.; IF DAE_D=. then do; DAE_N1 = .; DAE_N2 = .; end;
 
      if DDE_D_HOF = 0   AND DDE_N_HOF>0   THEN DDE_D_HOF=.;   IF DDE_D_HOF <=0   then DDE_N_HOF = . ;
      if DDE_D_DEMEN = 0 AND DDE_N_DEMEN>0 THEN DDE_D_DEMEN=.; IF DDE_D_DEMEN <=0 then DDE_N_DEMEN = . ;
      if DDE_D_CRF = 0   AND DDE_N_CRF>0   THEN DDE_D_CRF=.;   IF DDE_D_CRF <=0   then DDE_N_CRF = .;

      if AAP_D_20_44 = 0 AND AAP_N_20_44>0 THEN AAP_D_20_44=.; IF AAP_D_20_44<=0 then AAP_N_20_44 = . ;    
      if AAP_D_45_64 = 0 AND AAP_N_45_64>0 THEN AAP_D_45_64=.; IF AAP_D_45_64<=0 then AAP_N_45_64 = . ;   
      if AAP_D_65 = 0    AND AAP_N_65>0    THEN AAP_D_65=.;    IF AAP_D_65<=0    then AAP_N_65 = .;

      if IET_D_13_17 = 0 AND (IET_NI_13_17>0 OR IET_NE_13_17>0) THEN IET_D_13_17=.; IF IET_D_13_17<=0 then do; IET_NI_13_17 = .;  IET_NE_13_17 = .; end;
      if IET_D_18 = 0    AND (IET_NI_18>0 OR IET_NE_18>0)       THEN IET_D_18=.;    IF IET_D_18<=0    then do; IET_NI_18 = .;     IET_NE_18 = .;    end;
     
      if PCE_D = 0 AND (PCE_N1>0 OR PCE_N2>0) THEN PCE_D=.; IF PCE_D<=0 then do; PCE_N1 = .; PCE_N2 = .; end;   
      if FUH_D = 0 AND (FUH_N1>0 OR FUH_N2>0) THEN FUH_D=.; IF FUH_D<=0 then do; FUH_N1 = .; FUH_N2 = .; end;


             *** Labels for Care Quality Measures ****; 
         
         Label ABA_D ='Denominator for Adult BMI Assessment';
         Label ABA_N ='Numerator for Adult BMI Assessment';

         Label COL_D ='Denominator for Colorectal Cancer Screening';
         Label COL_N ='Numerator for Colorectal Cancer Screening';

         Label BCS_D ='Denominator for Breast Cancer Screening: 52-69 Years';
         Label BCS_N ='Numerator for Breast Cancer Screening: 52-69 Years';

         Label OMW_D  ='Denominator for Osteoporosis Management in Women Who Had a Fracture';
         Label OMW_N  ='Numerator for Osteoporosis Management in Women Who Had a Fracture';
 
         Label CBP_D  ='Denominator for Controlling High Blood Pressure';
         Label CBP_N  ='Numerator for Controlling High Blood Pressure';
         Label PBH_D  ='Denominator for Persistence of Beta-Blocker Treatment After a Heart Attack';
         Label PBH_N  ='Numerator for Persistence of Beta-Blocker Treatment After a Heart Attack';

         Label CMC_D  ='Denominator for Cholesterol Management for Pts w/Cardio Conditions (CMC)';
         Label CMC_N1 ='Numerator 1 for CMC: LDL-C screening';
         Label CMC_N2 ='Numerator 2 for CMC: LDL-C level of <100 mg/dL';

         Label CDC_D1 ='Denominator 1 for Comprehensive Diabetes Care: HbA1c Testing';
         Label CDC_N1 ='Numerator 1 for Comprehensive Diabetes Care: HbA1c Testing';
         Label CDC_D2 ='Denominator 2 for Comprehensive Diabetes Care: HbA1c Poor Control >9%';
         Label CDC_N2 ='Numerator 2 for Comprehensive Diabetes Care: HbA1c Poor Control >9%';
         Label CDC_D3 ='Denominator 3 for Comprehensive Diabetes Care: HbA1c Good Control <7%';
         Label CDC_N3 ='Numerator 3 for Comprehensive Diabetes Care: HbA1c Good Control <7%';
         Label CDC_D4 ='Denominator 4 for Comprehensive Diabetes Care: Eye exam (retinal) performed';
         Label CDC_N4 ='Numerator 4 for Comprehensive Diabetes Care: Eye exam (retinal) performed';
         Label CDC_D5 ='Denominator 5 for Comprehensive Diabetes Care: LDL-C Screening';
         Label CDC_N5 ='Numerator 5 for Comprehensive Diabetes Care: LDL-C Screening';
         Label CDC_D6 ='Denominator 6 for Comprehensive Diabetes Care: LDL-C Control <100mg/dL';
         Label CDC_N6 ='Numerator 6 for Comprehensive Diabetes Care: LDL-C Control <100mg/dL';
         Label CDC_D7 ='Denominator 7 for Comprehensive Diabetes Care: Medical Attention for Nephropathy';  
         Label CDC_N7 ='Numerator 7 for Comprehensive Diabetes Care: Medical Attention for Nephropathy'; 
         Label CDC_D8 ='Denominator 8 for Comprehensive Diabetes Care: Blood pressure control <130/80 mm Hg';
         Label CDC_N8 ='Numerator 8 for Comprehensive Diabetes Care: Blood pressure control <130/80 mm Hg';
         Label CDC_D9 ='Denominator 9 for Comprehensive Diabetes Care: Blood pressure control <140/90 mm Hg'; 
         Label CDC_N9 ='Numerator 9 for Comprehensive Diabetes Care: Blood pressure control <140/90 mm Hg';

         Label SPR_D  ='Denominator for Use of Spirometry Testing in Assessment/Diagnosis of COPD';
         Label SPR_N  ='Numerator for Use of Spirometry Testing in Assessment/Diagnosis of COPD';

         Label PCE_D  ='Denominator for Pharmacotherapy Management of COPD Exacerbation (PCE)';
         Label PCE_N1 ='Numerator 1 for PCE: Systemic Corticosteroid'; 
         Label PCE_N2 ='Numerator 2 for PCE: Bronchodilator'; 

         Label FUH_D  ='Denominator for Follow-Up after Hospitalization for Mental Illness (FUH)';
         Label FUH_N1 ='Numerator 1 for FUH: 30-day follow-up';
         Label FUH_N2 ='Numerator 2 for FUH: 7-day follow-up';

         Label AMM_D  ='Denominator for Antidepressant Medication Management (AMM)';
         Label AMM_N1 ='Numerator 1 for AMM: Optimal Practitioner Contacts for Medication Management';
         Label AMM_N2 ='Numerator 2 for AMM: Effective Acute Phase Treatment';

         Label GSO_D  ='Denominator for Glaucoma Screening in Older Adults (GSO)';
         Label GSO_N  ='Numerator for Glaucoma Screening in Older Adults (GSO)';

         Label ART_D  ='Denominator for Disease Modifying Anti-Rheumatic Drug Therapy for Rheumatoid Arthritis';
         Label ART_N  ='Numerator for Disease Modifying Anti-Rheumatic Drug Therapy for Rheumatoid Arthritis';
    
         Label MPM_D1 ='Denominator 1 for Monitor Persistent Medications: ACE Inhibitors or ARBs Medications';
         Label MPM_N1 ='Numerator 1 for Monitor Persistent Medications: ACE Inhibitors or ARBs Medications';
         Label MPM_D2 ='Denominator 2 for Monitor Persistent Medications: Digoxin';
         Label MPM_N2 ='Numerator 2 for Monitor Persistent Medications: Digoxin';
         Label MPM_D3 ='Denominator 3 for Monitor Persistent Medications: Diuretics';
         Label MPM_N3 ='Numerator 3 for Monitor Persistent Medications: Diuretics';
         Label MPM_D4 ='Denominator 4 for Monitor Persistent Medications: Anticonvulsants'; 
         Label MPM_N4 ='Numerator 4 for Monitor Persistent Medications: Anticonvulsants';

         Label DAE_D  ='Denominator for Use of High-Risk Medications in the Elderly (DAE)';
         Label DAE_N1 ='Numerator 1 for DAE: At Least One Prescription'; 
         Label DAE_N2 ='Numerator 2 for DAE: At Least Two Prescriptions'; 

              *** DDE: Drug-Disease Interactions in Elderly ***;

         label DDE_D_HOF   ='Denominator 1 for DDE: History of Falls + Tricyclic Antidepressants/Antipsychotics/Sleep Agents'; 
         label DDE_N_HOF   ='Numerator 1 for DDE: History of Falls + Tricyclic Antidepressants/Antipsychotics/Sleep Agents'; 
         label DDE_D_DEMEN ='Denominator 2 for DDE: Dementia + Tricyclic Antidepressants/Anticholineric Agents';
         label DDE_N_DEMEN ='Numerator 2 for DDE: Dementia + Tricyclic Antidepressants/Anticholineric Agents';
         label DDE_D_CRF   ='Denominator 3 for DDE: Chronic Renal Failure + Nonaspirin NSAIDs/Cox-2 Selective NSAIDs';
         label DDE_N_CRF   ='Numerator 3 for DDE: Chronic Renal Failure + Nonaspirin NSAIDs/Cox-2 Selective NSAIDs';
 
         label AAP_D_20_44 ='Denominator for Adults Access to Preventive/Ambulatory Health Serv: Ages 20-44';
         label AAP_N_20_44 ='Numerator for Adults Access to Preventive/Ambulatory Health Serv: Ages 20-44'; 
         label AAP_D_45_64 ='Denominator for Adults Access to Preventive/Ambulatory Health Serv: Ages 45-64'; 
         label AAP_N_45_64 ='Numerator for Adults Access to Preventive/Ambulatory Health Serv: Ages 45-64'; 
         label AAP_D_65    ='Denominator for Adults Access to Preventive/Ambulatory Health Serv: Ages 65+'; 
         label AAP_N_65    ='Numerator for Adults Access to Preventive/Ambulatory Health Serv: Ages 65+'; 

              *** AOD: Alcohol and Other Drug Dependence ***;

         label IET_D_13_17  ='Denominator for Initiation and Engagement of AOD Treatment: 13-17 years';
         label IET_NI_13_17 ='Numerator for: Initiation of AOD Treatment -13-17 years';
         label IET_NE_13_17 ='Numerator for: Engagement of AOD Treatment -13-17 years';
         label IET_D_18     ='Denominator for Initiation/Engagement of AOD Dependence Treatment: 18+ years';
         label IET_NI_18    ='Numerator for: Initiation of AOD Treatment-18+ years';
         label IET_NE_18    ='Numerator for: Engagement of AOD Treatment-18+ years';

              *** FSP variables - Numerators Only ***;

        label FSP_N_BWLS ='Frequent Selected Procedures: Bariatric Weight Loss Surgery';
        label FSP_N_CABG = 'Frequency of Selected Procedure: CABG';
        label FSP_N_PTCA = 'Frequency of Selected Procedure: PTCA';
        label FSP_N_CC   = 'Frequency of Selected Procedure: Cardiac Catheterization';
        label FSP_N_CE   = 'Frequency of Selected Procedure: Carotid Endarterectomy';
        label FSP_N_OCH  = 'Frequency of Selected Procedure: Open Cholecystectomy';
        label FSP_N_CCH  = 'Frequency of Selected Procedure: Closed Cholecystectomy';
        label FSP_N_BS   = 'Frequency of Selected Procedure: Back Surgery';
        label FSP_N_AH   = 'Frequency of Selected Procedure: Abdominal Hysterectomy';
        label FSP_N_VH   = 'Frequency of Selected Procedure: Vaginal Hysterectomy';
        label FSP_N_PROS = 'Frequency of Selected Procedure: Prostatectomy';
        label FSP_N_THR  = 'Frequency of Selected Procedure: Total Hip Replacement (THR)';
        label FSP_N_TKR  = 'Frequency of Selected Procedure: Total Knee Replacement (TKR)';
        label FSP_N_MAST = 'Frequency of Selected Procedure: Mastectomy';
        label FSP_N_LUMP = 'Frequency of Selected Procedure: Lumpectomy';

        label IPU_T_ACDI   = 'Inpat Utili Gen Hosp/Acute Care- Discharges';
        label IPU_T_ACDY   = 'Inpat Utili Gen Hosp/Acute Care- Days';
        label IPU_T_ACSDI  = 'Inpat Utili Gen Hosp/Acute Care- Surgery Discharges';
        label IPU_T_ACSDY  = 'Inpat Utili Gen Hosp/Acute Care- Surgery Days';
        label IPU_T_ACMEDI = 'Inpat Utili Gen Hosp/Acute Care- Medicine Discharges';
        label IPU_T_ACMEDY = 'Inpat Utili Gen Hosp/Acute Care- Medicine Days';
        label IPU_T_ACMADI = 'Inpat Utili Gen Hosp/Acute Care- Maternity Discharges';
        label IPU_T_ACMADY = 'Inpat Utili Gen Hosp/Acute Care- Maternity Days';

        label AMB_T_OV    = 'Ambulatory Care- Outpatient Visits';
        label AMB_T_ED    = 'Ambulatory Care- Emergency Department Visits';

        label IAD_N_SVCANY = 'Alcohol/Other Drug Serv: Pct Members Receiv Any Serv';
        label IAD_N_SVCIP  = 'Alcohol/Other Drug Serv: Pct Members Receiv Inpatient Serv';
        label IAD_N_SVCINT = 'Alcohol/Other Drug Serv: Pct Members Receiv Intensive Outpatient Serv';
        label IAD_N_SVCAMB = 'Alcohol/Other Drug Serv: Pct Members Receiv Outpatient and ED Serv';

        label MPT_N_ANYMHS = 'Mental Health Utilization: Pct Members Receiv Any Serv';
        label MPT_N_IPMHS  = 'Mental Health Utilization: Pct Members Receiv Inpatient Serv';
        label MPT_N_IMHS   = 'Mental Health Utilization: Pct Members Receiv Intensive Outpatient Serv';
        label MPT_N_EDHS   = 'Mental Health Utilization: Pct Members Receiv Outpatient and ED Serv';

        label ABX_T_RX     = 'Total Number of Antibiotic Prescriptions';
        label ABX_T_RXDY   = 'Total days supplied for all antibiotic prescriptions';
        label ABX_T_RXCRN  = 'Total number of prescriptions for antibiotics of concern';
        label ABX_T_QUINO  = 'Antibiotics of Concern-Quinolones';
        label ABX_T_CEPHA  = 'Antibiotics of Concern-Cephalosporins 2nd- 4th Generation';
        label ABX_T_AZITH  = 'Antibiotics of Concern-Azithromycin and Clarithromycin';
        label ABX_T_AMOXI  = 'Antibiotics of Concern-Amoxicillin/Clavulanate';
        label ABX_T_KETOL  = 'Antibiotics of Concern-Ketolides';
        label ABX_T_CLIND  = 'Antibiotics of Concern-Clindamycin';
        label ABX_T_CMISC  = 'Miscellaneous Antibiotics of Concern';
        label ABX_T_ABSOR  = 'All Other Antibiotics -Absorbable Sulfonamides';
        label ABX_T_AMINO  = 'All Other Antibiotics -Aminoglycosides';
        label ABX_T_1GNCE  = 'All Other Antibiotics -FirstGeneration Cephalosporins';
        label ABX_T_LINCO  = 'All Other Antibiotics -Lincosamides (other than Clindamycin)';
        label ABX_T_MACRO  = 'All Other Antibiotics -Macrolides (other than Azithromycin and Clarithromycin)';
        label ABX_T_PENIC  = 'All Other Antibiotics -Penicillins';
        label ABX_T_TETRA  = 'All Other Antibiotics -Tetracyclines';
        label PCR_IHS  = 'Plan All-Cause Readmissions: Count of Index Hospital Stays';
        label PCR_CDR  = 'Plan All-Cause Readmissions: Count of 30-Day Readmissions specifications';
        label PCR_AAPR = 'Plan All-Cause Readmissions: Average Adjusted Probability of Readmission Specifications';

        drop gender short_hic invalid_hic hic_org _TYPE_ _FREQ_ ;  

        proc sort; by hic_number;
 
*** Read In Denominator File ***;

data denom0; set new.hedis10denom;

     proc sort; by hic_number;

data hed10(drop=hic_number); merge b0(in=ok) denom0; by hic_number;

     if ok;

     if denom_flag=. then denom_flag=0;
     
     *** Add State and Region Variables ***;

    if state_code='01' then state_ab='AL' ;    if state_code='02' then state_ab='AK' ;
    if state_code='03' then state_ab='AZ' ;    if state_code='04' then state_ab='AR' ;
    if state_code='05' then state_ab='CA' ;    if state_code='06' then state_ab='CO' ;
    if state_code='07' then state_ab='CT' ;    if state_code='08' then state_ab='DE' ;
    if state_code='09' then state_ab='DC' ;    if state_code='10' then state_ab='FL' ;

    if state_code='11' then state_ab='GA' ;    if state_code='12' then state_ab='HI' ;
    if state_code='13' then state_ab='ID' ;    if state_code='14' then state_ab='IL' ;
    if state_code='15' then state_ab='IN' ;    if state_code='16' then state_ab='IA' ;
    if state_code='17' then state_ab='KS' ;    if state_code='18' then state_ab='KY' ;
    if state_code='19' then state_ab='LA' ;    if state_code='20' then state_ab='ME' ;

    if state_code='21' then state_ab='MD' ;    if state_code='22' then state_ab='MA' ;
    if state_code='23' then state_ab='MI' ;    if state_code='24' then state_ab='MN' ;
    if state_code='25' then state_ab='MS' ;    if state_code='26' then state_ab='MO' ;
    if state_code='27' then state_ab='MT' ;    if state_code='28' then state_ab='NE' ;
    if state_code='29' then state_ab='NV' ;    if state_code='30' then state_ab='NH' ;

    if state_code='31' then state_ab='NJ' ;    if state_code='32' then state_ab='NM' ;
    if state_code='33' then state_ab='NY' ;    if state_code='34' then state_ab='NC' ;
    if state_code='35' then state_ab='ND' ;    if state_code='36' then state_ab='OH' ;
    if state_code='37' then state_ab='OK' ;    if state_code='38' then state_ab='OR' ;
    if state_code='39' then state_ab='PA' ;    if state_code='40' then state_ab='PR';

    if state_code='41' then state_ab='RI' ;    if state_code='42' then state_ab='SC' ;
    if state_code='43' then state_ab='SD' ;    if state_code='44' then state_ab='TN' ;
    if state_code='45' then state_ab='TX' ;    if state_code='46' then state_ab='UT' ;
    if state_code='47' then state_ab='VT' ;    if state_code='48' then state_ab='GU';
    if state_code='49' then state_ab='VA' ;    if state_code='50' then state_ab='WA' ;

    if state_code='51' then state_ab='WV' ;    if state_code='52' then state_ab='WI' ;
    if state_code='53' then state_ab='WY' ;    


    length region9 region4 $ 25; 

    if state_ab in ('CT','MA','ME','NH','RI','VT')                then region9='1.New England';
    if state_ab in ('NJ','NY','PA')                               then region9='2.Mid Atlantic'; 
    if state_ab in ('WI','MI','IL','IN','OH')                     then region9='3.East North Central'; 
    if state_ab in ('ND','SD','NE','KS','MN','IA','MO')           then region9='4.West North Central'; 
    if state_ab in ('DE','MD','DC','FL','GA','NC','SC','VA','WV') then region9='5.South Atlantic';
    if state_ab in ('KY','TN','MS','AL')                          then region9='6.East South Central'; 
    if state_ab in ('OK','AR','TX','LA')                          then region9='7.West South Central';
    if state_ab in ('MT','ID','WY','NV','UT','CO','AZ','NM')      then region9='8.Mountain'; 
    if state_ab in ('WA','OR','CA','HI','AK')                     then region9='9.Pacific';

    if region9='1.New England' or 
       region9='2.Mid Atlantic'        then region4='Region 1: Northeast';
    if region9='3.East North Central' or 
       region9='4.West North Central'  then region4='Region 2: Midwest';
    if region9='5.South Atlantic' or 
       region9='6.East South Central' or 
       region9='7.West South Central' then region4='Region 3: South';
    if region9='8.Mountain' or 
       region9='9.Pacific'             then region4='Region 4: West';

     zip5=1*substr(bene_zip_cd,1,5);  ** will add zip info when analysing **;

     proc sort; by zip5;

data zip; set new.zipinfo;

     proc sort; by zip5;

data new.hedis2010; merge hed10(in=ok) zip; by zip5;

     if ok;

     proc contents varnum;
          title 'HEDIS2010 analysis dataset';

     proc freq;
          tables totmonth denom_flag plan_type org_id;
          title 'HEDIS2010 Analysis Dataset';

endsas;